package example.demo.controller;

import demo.rao.mideng.annotation.RaoMiDeng;
import example.demo.aop.LogAnno;
import example.demo.entity.User;
import example.demo.service.UserService;
import org.springframework.aop.framework.AopContext;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/system/user")
public class UserController {
    @Autowired
    UserService userService;

    /*
     *   http://localhost:8080/api/system/user/insertOne
     *  {
     *     "password": "123kk",
     *     "username": "懒羊羊"
     *  }
     */
    @RequestMapping("/insertOne")
    @LogAnno
    public String insertOne(@RequestBody User user) {
        /**
         * <? @EnableAspectJAutoProxy(exposeProxy = true)主要目的debug
         */
        Object o = AopContext.currentProxy();
        int res = userService.insertOne(user);
        if (res == 0) {
            return "添加失败";
        } else {
            return "添加成功";
        }
    }
}

